import requests
from lxml import etree
url = 'http://www.boxofficecn.com/boxoffice2019'
headers = {
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36',
}
res = requests.get(url, headers=headers)
html = res.content.decode()
# 提取数据
tree = etree.HTML(html)
# 切片去除空行
tr_list = tree.xpath('//table/tbody/tr')[1:-1]
for tr in tr_list:
    # 当前有的td中为空  你可以使用异常处理去过滤掉 或者使用判断  列表长度大于0你就取
    print(tr.xpath('./td[1]/text()'), tr.xpath('./td[2]/text()'),tr.xpath('./td[3]/text()'),tr.xpath('./td[4]/text()'))
